#! /bin/bash

# vPresent is an immersive presentation creation and display application.
# Copyright (C) 2007 by Infiscape Corporation
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# vpresentd init file for vpresentd
#
# chkconfig: 345 50 50
# description: The vpresentd render server displays graphics distributed on \
#              a cluster by OpenSG.
# pidfile: /var/run/vpresentd.pid

# To install:
#update-rc.d ssh multiuser >/dev/null

#. /etc/init.d/functions
. /lib/lsb/init-functions


RETVAL=0

prog="vpresentd"

start() {
   echo -n $"Starting $prog: "

   # Because the Infiscape Cluster Control Daemon is a python script,
   # the daemon function does not correctly detect if the server is running.
   # In order to get around this limitation we assume that if the pid
   # is found in /proc, the server is already running happy and return success.
   pid=
   if [ -f /var/run/$prog.pid ]; then
      local line p
      read line < /var/run/$prog.pid
      for p in $line ; do
         [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
      done
   fi

   [ -n "${pid:-}" ] && success $"prog startup" && echo && return 0

   #daemon $prog
   start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd
   RETVAL=$?
   echo
   [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
   return $RETVAL
}

stop() {
   echo -n $"Stopping $prog: "
   start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/sshd.pid
   #killproc $prog
   RETVAL=$?
   echo
   [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
   return $RETVAL
}

restart() {
   #killproc -HUP $prog
   start-stop-daemon --stop --signal 1 --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd
}

case "$1" in
   start)
      start
      ;;
   stop)
      stop
      ;;
   restart)
      restart
      ;;
   status)
      status $prog
      ;;
   *)
      echo $"Usage: $0 {start|stop|status|restart}"
      exit 1
esac

exit $?
